package CTRLayer;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * Controller class for products
 * 
 * @author (AF, RA, KP, RL) 
 * @version (2012.06.05)
 */
public class PersonCTR
{
    private PersonCollection persons;

     /**
     * Constructor for objects of class PersonCTR
     */
    public PersonCTR()
    {
        persons = PersonCollection.getInstance();
    }

    /**
     * adds a Customer to container of persons
     * 
     * @param name name of Person
     * @param address address of Person
     * @param phoneNo phoneNo of Person
     * @param email email of Person
     * @param customerType customerType of Person
     * @param city city of Person
     * @param postalCode postalCode of Person
     * 
     * @return none
     */
    public void addCustomer(String name, String address, String phoneNo, String email, 
                            String customerType, String city, int postalCode)
    {
        Customer customer = new Customer(name, address, phoneNo, email, customerType, 
                                         city, postalCode);
        persons.addPerson(customer);
    }
    
    /**
     * adds a Salesman to container of persons
     * 
     * @param name name of Salesman
     * @param address address of Salesman
     * @param phoneNo phoneNo of Salesman
     * @param email email of Salesman
     * @param department department of Salesman
     * @param city city of Salesman
     * @param postalCode postalCode of Salesman
     * 
     * @return none
     */
    public void addSalesman(String name, String address, String phoneNo, String email, 
                            String department, String city, int postalCode)
    {
        Salesman salesman = new Salesman(name, address, phoneNo, email, department, city, postalCode);
        persons.addPerson(salesman);
    }
    
    /**
     * adds a Supplier to container of persons
     * 
     * @param name name of Supplier
     * @param address address of Supplier
     * @param phoneNo phoneNo of Supplier
     * @param email email of Supplier
     * @param product product of Supplier
     * @param city city of Supplier
     * @param postalCode postalCode of Supplier
     * 
     * @return none
     */
    public void addSupplier(String name, String address, String phoneNo, 
                            String email, String product, String city, int postalCode)
    {
        Supplier supplier = new Supplier(name, address, phoneNo, email, product, city, postalCode);
        persons.addPerson(supplier);
    }
    
    /**
     * finds a person
     * 
     * @param phoneNo phoneNo of person to be found
     * 
     * @return person as Person with phoneNo
     */
    public Person findPerson(String phoneNo)
    {
        Person person = persons.findPerson(phoneNo);
        return person;
    }
    
    /**
     * deletes a person
     * 
     * @param phoneNo phoneNo of person to be deleted
     * 
     * @return person to be deleted with phoneNo
     */
    public boolean deletePerson(String phoneNo)
    {
        return persons.deletePerson(phoneNo);
    }
    
    /**
     * lists all persons in person container
     * 
     * @param none
     * 
     * @return persons as ArrayList
     */
    public ArrayList<Person> listAllPersons()
    {
        return persons.listAllPersons();
    }
    
    /**
     * test method with default data for persons
     * 
     * @param none
     * 
     * @return none
     */
    public void testAddPersons()
    {
        addCustomer("Andreas", "Christiansgade", "10", "andreas", "Haandvaerker", "Aalborg", 9000);
        addCustomer("Rasmus", "Christiansgade", "20", "andreas", "Haandvaerker", "Aalborg", 9000);
        addCustomer("Kasper", "Christiansgade", "30", "andreas", "Haandvaerker", "Aalborg", 9000);
        addSalesman("Rana", "Hej", "40", "andreas", "Byggecenter", "Aalborg", 9000);
    }
}
